<template>
  <el-config-provider :locale="zhCn">
    <router-view />
  </el-config-provider>
</template>

<script lang="ts" setup>
import zhCn from "element-plus/es/locale/lang/zh-cn";
import { ElConfigProvider } from "element-plus";
import { useUserStore } from "./store/modules/user";
import { storeToRefs } from "pinia";

const userStore = useUserStore();
const { token } = storeToRefs(userStore);

onMounted(() => {
  if (token.value) {
    userStore.actionUserInfo();
  }
  // 检查浏览器是否支持 Page Visibility API
  if (typeof document.hidden !== "undefined") {
    // 监听页面可见性变化事件
    document.addEventListener("visibilitychange", () => {
      if (document.hidden) {
        localStorage.setItem("idle-date", String(Date.now()));
      } else {
        const idleDate = localStorage.getItem("idle-date");
        const timestamp = Date.now(); // 当前时间戳
        // 比较两个时间戳的差异是否大于 10 分钟
        if (idleDate && Math.abs(timestamp - Number(idleDate)) > 600000) {
          location.reload();
        }
      }
    });
  } else {
    console.log("浏览器不支持 Page Visibility API");
  }
});
</script>
<style lang="scss">
body {
  --el-border-color-light: #e1e1e5;
  .el-tabs--card {
    height: 100% !important;
    box-sizing: border-box;
    .el-tabs__content {
      border: 1px solid #e1e1e5;
      border-top: none;
      border-radius: 0 0 6px 6px;
    }
    .el-tabs__header {
      margin-bottom: 0;
    }
    .el-tab-pane {
      height: 100%;
      width: 100%;
      overflow: hidden;
    }
    .el-tabs__nav {
      overflow: hidden;
    }
    .el-tabs__header {
      .el-tabs__item {
        min-width: 96px;
        background-color: #f9f9f9;
        border-bottom: 1px solid var(--el-border-color-light);
      }
      .el-tabs__item.is-active {
        border-bottom: 1px solid transparent;
        background-color: #fff;
        font-weight: bold;
      }
    }
  }
  .el-message-box {
    --el-messagebox-border-radius: 10px;
    padding: 0;
    .el-message-box__header {
      height: 30px;
      padding-bottom: 0;
      background-color: #e5f1f5;
    }
    .el-message-box__title {
      height: 30px;
      line-height: 30px;
      font-size: 14px;
      padding-left: 10px;
      font-weight: normal;
    }
    .el-message-box__headerbtn {
      height: 34px;
      width: 34px;
      font-size: 18px;
    }
    .el-message-box__container {
      padding: 10px 6px;
    }
    .el-message-box__container .el-icon {
      font-size: 22px;
    }
    .el-message-box__btns {
      border-top: 1px solid #e1e1e5;
      padding: 10px;
      .el-button {
        height: 30px !important;
        padding: 0 15px;
      }
    }
  }
  .el-dialog {
    border-radius: 10px !important;
    padding: 0;
    .el-dialog__header {
      padding: 0px;
      height: 30px;
      padding-left: 15px;
      background-color: #e5f1f5;
      border-radius: 10px 10px 0 0 !important;
    }
    .el-dialog__title {
      height: 30px;
      line-height: 30px;
      font-size: 14px;
      font-weight: normal;
    }
    .el-dialog__headerbtn {
      width: 34px;
      height: 34px;
      top: 0px;
    }
    .el-dialog__close {
      font-weight: bold;
      font-size: 17px;
    }
    .el-dialog__body {
      padding: 10px 15px;
    }
    .el-dialog__footer {
      border-top: 1px solid #e1e1e5;
      padding: 10px;
      .el-button {
        height: 30px !important;
        padding: 0 15px;
      }
    }
  }
  .el-alert {
    padding-top: 5px !important;
    padding-bottom: 5px !important;
    .el-alert__title {
      color: #333 !important;
      font-size: 13px !important;
    }
  }
  .el-switch {
    height: auto !important;
    .el-switch__inner {
      .is-text {
        font-size: 14px !important;
      }
    }
  }
  .el-table {
    border-radius: 4px;
    overflow: hidden;
    --el-table-border-color: #e1e1e5;
    th.el-table__cell {
      background-color: #e5f1f5 !important;
      font-weight: normal;
      color: #333;
      font-size: 14px;
      .cell {
        font-weight: bold;
      }
    }
    .el-table__header {
      td.el-table__cell:first-child {
        border-radius: 10px 0 0 0;
      }
      td.el-table__cell:last-child {
        border-radius: 0 10px 0 0;
      }
    }
    .el-table__header {
      th.el-table__cell {
        div {
          font-size: 13px;
        }
      }
    }
    td.el-table__cell {
      padding: 8px 0;
    }
  }
  .el-checkbox {
    font-size: 16px !important;
  }
  .el-statistic__content {
    line-height: normal !important;
  }
  .el-notification {
    cursor: pointer;
  }
  .el-button [class*="el-icon"] + span {
    margin-left: 2px !important;
  }
  .el-button + .el-button {
    margin-left: 10px !important;
  }
  .el-button--small {
    --el-button-size: 27px;
    padding: 6px 10px;
    font-size: 14px;
  }
  .el-input,
  .el-textarea,
  .el-date-editor,
  .el-select {
    --el-input-bg-color: #f4f7f8;
    --el-fill-color-blank: #f4f7f8;
  }
  .el-select--small {
    .el-select__wrapper {
      padding: 6px 8px;
    }
  }
}
.el-popper {
  max-width: 400px !important;
}
</style>
